package com.view.houseon;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


import com.presentacion.houseon.R;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;


public class VideoActivity extends Activity {
	
	
	private MjpegView mv;
	Thread	thread;
	Handler handler;
	boolean cancel;
	int cptfichier=0;
	TextView txt;
	LinearLayout linear; 
	public static  Bitmap test;	
	
    OutputStream fOut = null;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		try {
			
			//String URL = "http://shibuya.ipcam.jp:60001/nphMotionJpeg?Resolution=320x240&Quality=Standard";
			String URL = "http://192.168.43.66:11341/cam_1.cgi"; 

	        final String path = Environment.getExternalStorageDirectory().toString();
	        
	       //quitar titulo de ventana 
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
	                             WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        
	 			 
	        setContentView(R.layout.activity_video);
			 
			    mv = new MjpegView(this); 
		        
		        LinearLayout midLL = (LinearLayout)findViewById(R.id.Surface1);
		     //   LinearLayout midLL = new LinearLayout(this); 
		        midLL.findViewById(R.id.Surface1); 
		        midLL.addView(mv);
		       // midLL.addView(new MjpegView(this));
		     
		        mv.setSource(MjpegInputStream.read(URL));
		        mv.setDisplayMode(MjpegView.TAM_OK);
		        mv.showFps(true);
		} catch (Exception e) {
			// TODO: handle exception
			System.out.print(e.getMessage());
			onPause();
		}
		  
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.video, menu);
		return true;
	}
	
	public void onPause() {
		super.onPause();
		mv.stopPlayback();
		
	}
	public void onCancel(DialogInterface arg0) {
		cancel=true;	
		super.onPause();
		mv.stopPlayback();
		
	}

}
